<?php
/**
 * 商圈管理
 * @author Ice iceinto@mallog.com.cn
 */
class BusModel extends BaseModel
{
	//自动验证
	protected $_validate = array(
			array('name', 'require', '名称必须！',self::MUST_VALIDATE),
			array('province', 'require', '省必须！',self::MUST_VALIDATE),
			array('city', 'require', '市必须！',self::MUST_VALIDATE),
			array('area', 'require', '区必须！',self::MUST_VALIDATE),
			array('name','','名称已经存在！',0,'unique',self::MODEL_BOTH),
	);
	public function getAllData ()
	{
		return $this->field(
				'm_bus.id,
				m_bus.name,
				m_bus.city,
				m_city.`name` as cityName,
				m_province.`name` as provinceName,
				m_area.`name` as areaName')
				->join('LEFT JOIN m_city ON m_bus.city = m_city.`code`')
				->join('LEFT JOIN m_province ON m_bus.province = m_province.`code`')
				->join('LEFT JOIN m_area ON m_bus.area = m_area.`code`')
				->select();
	}
	public function getOnly ($map)
	{
		return $this->field(
				'm_bus.id,
				m_bus.name,
				m_bus.province,
				m_bus.city,
				m_bus.area,
				m_city.`name` as cityName,
				m_province.`name` as provinceName,
				m_area.`name` as areaName')
				->where($map)
				->join('LEFT JOIN m_city ON m_bus.city = m_city.`code`')
				->join('LEFT JOIN m_province ON m_bus.province = m_province.`code`')
				->join('LEFT JOIN m_area ON m_bus.area = m_area.`code`')
				->find();
	}
}